****
* Generate Dawes Panel
***

clear

	*** load relevant data
	
		
		use "$Replicationdirectory/_Work/TEMP/_data_bonds"
		
	
	
	 
	
 	
  
		
	**** calculate spreads for markets
		
					foreach x of global markets{
					
						gen ln_P_`x'_GBP_GBP=log(P_`x'_GBP_GBP)
						gen spread_P_`x'_london=P_london_GBP_GBP-P_`x'_GBP_GBP
						
						
						
						gen spread_`x'_london=ytm_`x'-ytm_london
						gen spread_`x'_london_lav=(ytm_`x'_lastavail-ytm_london_lastavail) 
						
		 
					 
					
					}
						
						
			   
		 
 	 
	
	**** build panel dataset with spread  
	
						foreach market of global markets{
						
						preserve 
							keep date   annual_coupon_`market'   P_`market'_GBP_GBP P_`market'_GBP_GBP_lastavail spread_`market'_london spread_`market'_london_lav  tradingday_london rel_liquidity_`market' liquidity_`market' ytm_`market'   P_`market'_GBP_GBP spread_P_`market'_london  default day_in_sample week month year 
							
							rename annual_coupon_`market' annual_coupon
							
							rename spread_`market'_london spread_ytm
							rename spread_`market'_london_lav spread_ytm_lastavail
							
							
							
							
							rename spread_P_`market'_london spread_P
					 
							
							rename rel_liquidity_`market' rel_liquidity
							
							rename P_`market'_GBP_GBP Price_GBP
							rename P_`market'_GBP_GBP_lastavail Price_GBP_lastvail

							
							rename liquidity_`market' liquidity_LESMOND
							
							replace liquidity_LESMOND=liquidity_LESMOND/100

							
							rename ytm_`market' ytm
							
							gen market="`market'"

							save "$Replicationdirectory/_Work/TEMP/liq_`market'", replace 
						restore 
						}
						
						
						 
						
						
						
						*** stack panel
						 clear
									
									foreach market of global markets{
									
										append using  "$Replicationdirectory/_Work/TEMP/liq_`market'"
									  
									}
									
									
									encode market, gen(market_enc)
									xtset market_enc date
									

									

									
										egen  myear= group(month year)
										egen  wyear=  group(week year)

										
										
										
					  
									
									
									
										save "$Replicationdirectory/_Work/TEMP/DAWES_PANEL_ytm", replace				

													
													
